package com.zzty.training.controller;

import com.zzty.training.entity.User;
import com.zzty.training.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    UserService userService;

    @RequestMapping(value="/getUser",method = RequestMethod.POST)
    public User getUser(User user,HttpServletRequest request){
        System.out.println(user);
       User user1=userService.getUserByName(user);
        HttpSession session = request.getSession();
        session.setAttribute("username",user1.getName());
        System.out.println(session.getAttribute("username"));
        System.out.println("111"+user1.toString());
       return user1;
    }


}
